package cn.edu.scau.cmi.chenjunlin.client.Experiment4.Example1;

import cn.edu.scau.cmi.chenjunlin.mterProgramming.Experiment4.Example1.China;
import cn.edu.scau.cmi.chenjunlin.mterProgramming.Experiment4.Example1.England;
import cn.edu.scau.cmi.chenjunlin.mterProgramming.Experiment4.Example1.USA;
import cn.edu.scau.cmi.chenjunlin.mterProgramming.Experiment4.Example1.UnitedCountry;
import cn.edu.scau.cmi.chenjunlin.mterProgramming.Experiment4.Example1.WorldOrganization;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class CompositeGUI extends Application{
	String countryName = null;
	WorldOrganization wo = null;
	public static void main(String[] args) {
		launch(args);
	}
	public void start(Stage stage){
		   TextArea ta1 = new TextArea();
		   Label lb1 = new Label();
		   Button bt1 = new Button();
		   Button bt2 = new Button();
		   lb1.setText("Country");
		   final ChoiceBox<String> cb1 = new ChoiceBox<String>(
		           FXCollections.observableArrayList("China", "USA", "England", "UN"));
		   final String[] greetings1 = new String[] { "China", "USA", "England", "UN" };
		   cb1.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>(){
				@Override
				public void changed(ObservableValue<? extends Number> arg0, Number arg1, Number arg2) {
						countryName = greetings1[arg2.intValue()];
                  }
 	    });
		   bt1.setText("Say Hello");
		   bt2.setText("Exit");
		   bt1.setOnAction((ActionEvent e) ->{
			   if(countryName.equals("China")) wo = new China();
			   else if(countryName.equals("USA")) wo = new USA();
			   else if(countryName.equals("England")) wo = new England();
			   else if(countryName.equals("UN")) wo =new UnitedCountry();
				ta1.appendText(wo.say());
		   });
		   bt2.setOnAction((ActionEvent e) -> {
			   System.exit(1);
		   });
		   GridPane grid = new GridPane();
	       grid.setPadding(new Insets(0, 0, 3, 4));
	       grid.add(ta1, 0, 0, 4, 1);
	       grid.add(lb1, 1, 1);
	       grid.add(cb1, 2, 1);
	       grid.add(bt1, 1, 2);
	       grid.add(bt2, 2, 2);
	       grid.setVgap(10);
	       grid.setHgap(10);
           stage.setScene(new Scene(grid, 400, 400));
	       stage.show();
	}
	
}
